package com.wnxy.sddfp.trade.controller;

import com.wnxy.sddfp.common.model.dto.trade.BorrowRecordDTO;
import com.wnxy.sddfp.common.model.page.PageVo;
import com.wnxy.sddfp.common.model.query.BorrowRecordQuery;
import com.wnxy.sddfp.common.model.vo.trade.BorrowRecordVo;
import com.wnxy.sddfp.common.result.Result;
import com.wnxy.sddfp.trade.service.IBorrowRecordService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 借款信息表 前端控制器
 * </p>
 *
 * @author Jet
 * @since 2024-02-20
 */
@RestController
@Api(tags = "交易中心")
@RequestMapping("/trade")
public class BorrowRecordController {
    private final IBorrowRecordService borrowRecordService;

    public BorrowRecordController(IBorrowRecordService borrowRecordService) {
        this.borrowRecordService = borrowRecordService;
    }

    @ApiOperation("借款申请")
    @PostMapping("/borrow/add")
    public Result addBorrowRecord(@RequestBody BorrowRecordDTO borrowRecordDTO) {
        borrowRecordService.addBorrowRecord(borrowRecordDTO);
        return Result.ok();
    }

    @ApiOperation("借款记录查询")
    @PostMapping("/trade/borrow/query/{current}/{size}")
    public Result<PageVo<BorrowRecordVo>> borrowRecordQuery(
            @PathVariable("current") Integer current,
            @PathVariable("size") Integer size,
            @RequestBody BorrowRecordQuery borrowRecordQuery) {
        PageVo<BorrowRecordVo> pages =
                borrowRecordService.borrowRecordQuery(current,size,borrowRecordQuery);
        return Result.ok(pages);
    }

    // 交易中心微服务提供管理员借款审核接口
    @ApiOperation("借款审核接口")
    @PutMapping("/trade/borrow/status")
    public Result verifyStatus(Long borrowRecordId, String status) {
        borrowRecordService.verifyStatus(borrowRecordId,status);
        return Result.ok();
    }
}












